package com.blog.controller.admin;

import com.blog.model.User;
import com.blog.service.UserService;
import org.apache.ibatis.jdbc.Null;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;
//import net.sf.json.JSONObject;


@Controller
@RequestMapping("/sync/")
public class SyncContorller {

    @Resource
    protected UserService userService;

    @RequestMapping("")
    public String index(HttpServletRequest request){
        List<User> list = new ArrayList<User>();
        List<User> userData = userService.findAll();
        for(User dlist:userData){
            String username = dlist.getUsername();
            if(!dlist.getUsername().equals("admin")){
                dlist.setUsername("china");
            }
            list.add(dlist);
        }
        request.setAttribute("data",list);
        return "/admin/sync/index";
    }

//    @RequestMapping("/json")
//    @ResponseBody
//    public String json(){
//        JSONObject result = new JSONObject();
//        result.element("user",1);
//        result.element("type", "message");
//        result.element("msg", "contentVal");
//        String resultStr=result.toString();
//        return resultStr;
//    }
}
